package com.byx.chatclient.manager;

import com.byx.chatclient.entity.MessagePo;
import com.byx.chatclient.entity.MessagePoDao;
import com.byx.chatclient.entity.message.Message;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * UserChatManager
 *
 * @author Superb
 * @date 2021/3/25 13:32
 */
public class UserChatRecordManager extends BaseBeanManager<MessagePo,String> {
    public UserChatRecordManager(AbstractDao<MessagePo, String> mDao) {
        super(mDao);
    }

    public List<MessagePo> queryChatRecord(String userId,String friendId){
        QueryBuilder<MessagePo> messagePoQueryBuilder = queryBuilder();
        messagePoQueryBuilder.where(
                messagePoQueryBuilder.or(
                        messagePoQueryBuilder.and(
                                MessagePoDao.Properties.SenderId.eq(friendId),
                                MessagePoDao.Properties.RecipientId.eq(userId)
                        ),
                        messagePoQueryBuilder.and(
                                MessagePoDao.Properties.SenderId.eq(userId),
                                MessagePoDao.Properties.RecipientId.eq(friendId)
                        )
                )
        );
        return messagePoQueryBuilder.list();
    }

    public List<MessagePo> queryGroupChatRecord(String groupId){
        return queryBuilder().where(MessagePoDao.Properties.RecipientId.eq(groupId)).list();
    }
}
